<script>
    import Menu from './components/layout/Menu.vue'
    export default{
        ready(){
            this.$set('categoryResource', this.$resource('/lesson/category{/id}'));
        },
        data(){
            return {
                categoryResource: {}
            }
        },
        components: {
            Menu,
        },
        events: {
            ckUpload: function (child) {
                CKFinder.modal({
                    chooseFiles: true,
                    language: 'zh-cn',
                    onInit: function (finder) {
                        finder.on('files:choose', function (evt) {
                            var url = evt.data.files.first().getUrl();
                            child.$set('category.thumb', url)
                        });

                        finder.on('file:choose:resizedImage', function (evt) {
                            var url = evt.data.resizedUrl;
                            child.$set('category.thumb', url)
                        });
                    }
                });
            },
            upload: function (child) {
                var opts = {
                    url: "/xSystem/upload",
                    type: "POST",
                    beforeSend: function () {
                        $("#loading").attr("class", "am-icon-spinner am-icon-pulse");
                    },
                    success: function (result, status, xhr) {

                        if (result.status == "0") {
                            alert(result.info);
                            $("#loading").attr("class", "am-icon-cloud-upload");
                            return false;
                        }

                        child.$set('category.thumb', result.info)

                        $("#loading").attr("class", "am-icon-cloud-upload");
                    },
                    error: function (result, status, errorThrown) {
                        alert('文件上传失败');
                    }
                }
                $('#thumb_upload').fileUpload(opts);
            }
        }
    }
</script>
